//
//  PullCoinViewController.m
//  AppleMarket
//
//  Created by yangy on 02/11/2018.
//  Copyright © 2018 szgsy. All rights reserved.
//

#import "PullCoinViewController.h"
// controller
#import "CoinListViewController.h"
#import "WithdrawViewController.h"
#import "ConversionViewController.h"
// model
#import "CoinAssetModel.h"

@interface PullCoinViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray<CoinAssetModel*> *dataArray;
@property (nonatomic, assign) NSInteger curIndex;

@end

@implementation PullCoinViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setNagivationBar];
    [self.view addSubview:self.tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
}

- (void) setNagivationBar
{
    //UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"提币",@"互转",@"划转"]];
    segment.frame = CGRectMake(0, 0, 225, 30);
    self.curIndex = segment.selectedSegmentIndex = 0;
    [[segment rac_signalForControlEvents:UIControlEventValueChanged] subscribeNext:^(__kindof UIControl * _Nullable x) {
        self.curIndex = segment.selectedSegmentIndex;
    }];
    //[titleView addSubview:segment];
    self.navigationItem.titleView = segment;
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.coinModels.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
    if(cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([UITableViewCell class])];
        cell.textLabel.font = kFontBold(17);
        cell.textLabel.textColor = kColorWithHex(0x0E304C);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    cell.textLabel.text = self.coinModels[indexPath.row].Unit;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 53;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    switch (self.curIndex) {
        case 0:
        {
            WithdrawViewController *withdrawVC = [[WithdrawViewController alloc] init];
            withdrawVC.coinModel = self.coinModels[indexPath.row];
            [self bh_PushViewController:withdrawVC hiddenTabbar:YES];
        }
            break;
        case 1:
            // 互转
        {
            ConversionViewController *conversionVC = [[ConversionViewController alloc] init];
            conversionVC.coinModel  = self.coinModels[indexPath.row];
            [self bh_PushViewController:conversionVC hiddenTabbar:YES];
        }
            break;
        case 2:
            
            break;
        default:
            break;
    }
}

- (UITableView *)tableView
{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        [_tableView setDelegate:self];
        [_tableView setDataSource:self];
        [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        [_tableView setTableFooterView:[UIView new]];
        [_tableView setSectionIndexColor:kColorWithHex(0x0E304C)];
    }
    return _tableView;
}

@end
